package com.wjk.cms.util.wx;/*
package com.wjk.cms.util.wx;

import com.hlt360.sale.app.service.sys.SysConfigService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@Slf4j
@Data
@Component
public class GlobalConfig  {
    @Autowired
    private  StringRedisTemplate redisTemplate;
    @Autowired
    private  SysConfigService sysConfigService;
    private static GlobalConfig instance ;

    @Value("${app.master-node}")
    private String masterNode;


    // 微信统一下单接口地址
    private String unifiedOrderUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";

    // 企业付款到零钱
    private String payUrl = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

    // 签名方式
    private String signType = "MD5";

    // 交易类型
    private String tradeTypeApp = "APP";

    private String tradeTypeXcx = "JSAPI";

    private String tradeTypeH5 = "MWEB";

    public static final String GLOBAL_CONFIG = "global_config";
    public static final String MECHID_REDIS_SUFFIX = "_config_mechid";
    public static final String MECHKEY_REDIS_SUFFIX = "_config_mechkey";
    public static final String GZHAPPID_REDIS_SUFFIX = "_config_gzhappid";
    public static final String GZHAPPSECRET_REDIS_SUFFIX = "_config_gzhappsecret";
    public static final String XCXAPPID_REDIS_SUFFIX = "_config_xcxappid";
    public static final String XCXAPPSECRET_REDIS_SUFFIX = "_config_xcxappsecret";
    public static final String APP_APPID_REDIS_SUFFIX = "_config_appappid";
    public static final String APP_APPSECRET_REDIS_SUFFIX = "_config_appappsecret";
    public static final String AGENTPOSTER_REDIS_SUFFIX = "_config_agentposter";
    public static final String CUSTOMERPOSTER_REDIS_SUFFIX = "_config_customerposter";
    public static final String BOSSCODE_REDIS_SUFFIX = "_config_bosscode";
    //发送钉钉消息  获取accessToken 配置后缀
    public static final String DINGTOKEN_REDIS_SUFFIX = "_config_dingtoken";
    public static final String NTC="ntc";
    public static final String YUANMU="yuanmu";
    public static final String NANTONG="nantong";

    public static final String TEMPLATEID_REDIS_SUFFIX = "_config_templateid";



    // 微信支付的商户id
    public static String MCH_ID(String channel) {
        String mchid = getByChannelSuffix(channel,MECHID_REDIS_SUFFIX);
        return mchid;
//        return mechIdConfg.get(channel);
    }

    // 微信支付的商户密钥
    public static String MCH_KEY(String channel) {
        String mchkey = getByChannelSuffix(channel,MECHKEY_REDIS_SUFFIX);
        return  mchkey;
//        return mchKeyConfg.get(channel);
    }

    // 微信统一下单接口地址
    public static String UNIFIED_ORDER_URL() {
        return instance.getUnifiedOrderUrl();
    }

    // 企业付款到零钱
    public static String PAY_URL() {
        return instance.getPayUrl();
    }

    // 签名方式
    public static String SIGN_TYPE() {
        return instance.getSignType();
    }

    // 交易类型
    public static String TRADE_TYPE_APP() {
        return instance.getTradeTypeApp();
    }

    public static String TRADE_TYPE_XCX() {
        return instance.getTradeTypeXcx();
    }

    public static String TRADE_TYPE_H5() {
        return instance.getTradeTypeH5();
    }

    // 公众号appid
    public static String GZH_APP_ID(String channel) {
        String appid = getByChannelSuffix(channel,GZHAPPID_REDIS_SUFFIX);
        return appid;
//        return gzhAppIdConfg.get(StringUtils.isBlank(channel)?"ntc":channel);
    }

    // 公众号secret
    public static String GZH_APP_SECRET(String channel) {

        String appKey = getByChannelSuffix(channel,GZHAPPSECRET_REDIS_SUFFIX);
        return appKey;
//        return gzhAppSecretConfg.get(StringUtils.isBlank(channel)?"ntc":channel);
    }

    // 小程序appid
    public static String XCX_APP_ID(String channel) {
        String appid = getByChannelSuffix(channel,XCXAPPID_REDIS_SUFFIX);
        return appid;

    }

    // 小程序secret
    public static String XCX_APP_SECRET(String channel) {

        String appKey = getByChannelSuffix(channel,XCXAPPSECRET_REDIS_SUFFIX);
        return appKey;

    }

    // APPappid
    public static String APP_APP_ID(String channel) {
        String appid = getByChannelSuffix(channel,APP_APPID_REDIS_SUFFIX);
        return appid;

    }

    // APPsecret
    public static String APP_APP_SECRET(String channel) {

        String appKey = getByChannelSuffix(channel,APP_APPSECRET_REDIS_SUFFIX);
        return appKey;

    }

    // 代理海报
    public static String POSTER_AGENT_URL(String channel) {
        String agentPoster = getByChannelSuffix(channel,AGENTPOSTER_REDIS_SUFFIX);
        return agentPoster;
//        return posterAgentConfg.get(StringUtils.isBlank(channel)?"ntc":channel);
    }

    // 客户海报
    public static String POSTER_CUSTOMER_URL(String channel) {
        String customerPoster = getByChannelSuffix(channel,CUSTOMERPOSTER_REDIS_SUFFIX);
        return customerPoster;
//        return posterCustomerConfg.get(StringUtils.isBlank(channel)?"ntc":channel);
    }

    public static String BOSS_USER_CODE(String channel){
        String bossCode = getByChannelSuffix(channel,BOSSCODE_REDIS_SUFFIX);
        return bossCode;
//        return bossCodeConfg.get(channel);
    }

    // 钉钉群accessToken
    public static String DINGDING_ACCESSTOKEN(String channel) {
        String accessToken = getByChannelSuffix(channel,DINGTOKEN_REDIS_SUFFIX);
        return accessToken;
    }
    private static String getByChannelSuffix(String channel,String suffix){

        channel = StringUtils.isBlank(channel)?"ntc":channel;
        String redisKey = channel + suffix;
        log.info("redisKey:"+redisKey);
        String value = instance.redisTemplate.opsForValue().get(redisKey);
        if(StringUtils.isBlank(value)){
            value = instance.sysConfigService.get(GLOBAL_CONFIG, redisKey);
            instance.redisTemplate.opsForValue().set(redisKey,value);
        }
        return value;
    }

    public static String MESSAGE_TEMPLATE(String channel) {

        String templateId = getByChannelSuffix(channel,TEMPLATEID_REDIS_SUFFIX);
        return templateId;

    }

    @PostConstruct
    public void init(){

        instance=this;
        // 关闭非主服务上的global初始化
        if (!"1".equals(masterNode)) {
            return;
        }
        log.info("初始化global配置开始---");
        Map<String, String> configMap = instance.sysConfigService.findByCfgGrp(GlobalConfig.GLOBAL_CONFIG);
        //System.out.println(configMap.toString());
        Set<String> keys = configMap.keySet();
        Iterator<String> it = keys.iterator();
        while(it.hasNext()){
            String key = it.next();
            redisTemplate.opsForValue().set(key,configMap.get(key));
        }
        log.info("初始化global配置结束---");
    }

}
*/
